package org.leitian.exception;

import lombok.extern.slf4j.Slf4j;
import org.leitian.result.JSONResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalException {

    @ExceptionHandler(value = RuntimeException.class)
    public JSONResult RuntimeException(RuntimeException e){
        e.printStackTrace();
        return JSONResult.error("连接超时");
    }

    @ExceptionHandler(value = NullPointerException.class)
    public JSONResult NullPointerException(NullPointerException e){
        e.printStackTrace();
        return JSONResult.error("吃鱼警告,null");
    }

    @ExceptionHandler(value = Exception.class)
    public JSONResult Exception(Exception e){
        e.printStackTrace();

        return JSONResult.error("系统开小差啦");
    }
    /**
     * 业务异常
     * 自定义异常
     */
    @ExceptionHandler(MyException.class)
    public JSONResult businessException(MyException e) {
        e.printStackTrace();
        return JSONResult.error(e.getMessage());
    }
}
